﻿

function main() {
    showLog("抖音(推荐私信)");
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var search = viewJson.search;
    var terminationNum = viewJson.terminationNum;
    var contentArr = viewJson.contentArr;
    AccessibilityEngine.sleepEngine(8000);//等待
    // chuSiHua(widget.pages.shouye.bugengxin);
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    var jixing = getXYByIdIndex(widget.pages.shouye.wode);
    ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    for (var i =0 ; i <search; i ++ ) {  // 循环滑动
        if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
            AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
        }
        if (jixing == 1) {// 判断机型
            var pressjixing = "press," + parseX(660) + "," + parseY(763);
            ScreenEngine.currency(pressjixing);
        } else if (jixing == 2) {
            ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); //从下往上滑动
        }
        if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
            AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
        }
 
      
        var termination = 0;
        var neirongList = [];
        aaa:while (termination < terminationNum) {
            if (AccessibilityEngine.checkUpId(widget.pages.pinglun.titleneirong) == ISTRUE) { //点赞小心
                var nameIdNum = AccessibilityEngine.getIdNum(widget.pages.pinglun.titleneirong);
                showLog('nameIdNum' + nameIdNum);
                for (var name = 0; name < nameIdNum; name++) {
                    var JSONneirong = AccessibilityEngine.getBoundsCenterIdIndex(widget.pages.pinglun.titleneirong, name);
                    neirongList.push(JSONneirong);
                }
                for (var nameI = 0; nameI < neirongList.length; nameI++) {
                    if (AccessibilityEngine.checkUpId(widget.pages.pinglun.titleneirong) == ISTRUE) { //点赞小心
                        var neirongListJSON = JSON.parse(neirongList[nameI]);
                        showLog(neirongListJSON);
                        var neirongListJSONcenterX = parseInt(neirongListJSON.centerX) + 200;
                        showLog(neirongListJSONcenterX);
                        showLog(neirongListJSON.centerY);
                        if (jixing == 1) {
                            if (neirongListJSON.centerY > 1100) {
                                showLog('错误点击');
                                continue;
                            }
                        }else {
                            if (neirongListJSON.centerY > 1500) {
                                showLog('错误点击');
                                continue;
                            }
                        }
						AccessibilityEngine.sleepEngine(3000);//等待
						if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
							AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
						}
						AccessibilityEngine.log("长恩前") 
                        ScreenEngine.swipe(parseX(200), parseY(362), parseX(200), parseY(362), 4000); //长恩
						AccessibilityEngine.log("长恩后") 
                        AccessibilityEngine.sleepEngine(3000);//等待
						
						if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
							AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
						}
                        if (AccessibilityEngine.checkUpIdText(widget.classText.widgetByClass.text1, "私信回复") == ISFALSE) {
						AccessibilityEngine.sleepEngine(3000);//等待
						if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
							AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
						}
                            showLog("私信回复==isfalse")
                            var pressCenter = "press," + neirongListJSONcenterX + "," + neirongListJSON.centerY;
                            ScreenEngine.currency(pressCenter);
                            AccessibilityEngine.sleepEngine(2000);//等待
							
						if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
							AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
						}
                            if (AccessibilityEngine.checkUpIdText(widget.classText.widgetByClass.text1, "私信回复") == ISTRUE) {
							AccessibilityEngine.sleepEngine(1000);//等待
							if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
								AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
							}
                                if (jixing == 1) {
                                    AccessibilityEngine.mockOnClickIdIndex(widget.classText.widgetByClass.text1, 2);
                                } else {
                                    var presshuifu = "press," + parseX(511 * 0.67) + "," + parseY(988 * 0.67);
                                    ScreenEngine.currency(presshuifu);
                                }
                            }else {
                                AccessibilityEngine.mockBack();
                                if (AccessibilityEngine.checkUpId(widget.pages.pinglun.fanhui1) == ISTRUE) {
                                    AccessibilityEngine.mockOnClickId(widget.pages.pinglun.fanhui1);
                                    showLog('广告详情返回2');
                                    AccessibilityEngine.sleepEngine(2000);
                                    if (AccessibilityEngine.checkUpId(widget.pages.pinglun.titleneirong) == ISTRUE) {
                                        AccessibilityEngine.mockBack();
                                    }
                                }
                                break aaa;
                            }
                        }else {
                            if (jixing == 1) {
                                AccessibilityEngine.mockOnClickIdIndex(widget.classText.widgetByClass.text1, 1);
                            } else {
                                var presshuifu = "press," + parseX(511 * 0.67) + "," + parseY(920 * 0.67);
                                ScreenEngine.currency(presshuifu);
                            }
                        }
                        AccessibilityEngine.sleepEngine(2000);//等待
                        if (AccessibilityEngine.checkUpId(widget.pages.shouye.fasong) == ISTRUE) {
                            AccessibilityEngine.mockBack();
                            continue;
                        }
                        AccessibilityEngine.sleepEngine(3000);//等待
						if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
							AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
						}
                        if (AccessibilityEngine.checkUpId(widget.pages.shouye.fuzhikuang) == ISTRUE) {
                            var search2 = contentArr[Math.floor(Math.random()*contentArr.length)];
                            AccessibilityEngine.mockEditId(widget.pages.shouye.fuzhikuang, search2); //赋值
                            AccessibilityEngine.sleepEngine(1000);//等待
                            AccessibilityEngine.mockOnClickId(widget.pages.tongchengyemian.sixingei); // 发送
							ScreenEngine.swipe(parseX(210), parseY(545), parseX(210), parseY(390), 500); //从下往上滑动
                            AccessibilityEngine.sleepEngine(1000);//等待
                            termination++;
                            if (termination >= terminationNum) {
                                AccessibilityEngine.mockBack();8
                                break aaa;
                            }
                        }
                        if (AccessibilityEngine.checkUpId(widget.pages.shouye.fuzhikuang) == ISTRUE) {
                            AccessibilityEngine.mockBack();
                            AccessibilityEngine.sleepEngine(1000);
                            if (AccessibilityEngine.checkUpId(widget.pages.shouye.fuzhikuang) == ISTRUE) {
                                AccessibilityEngine.mockBack();
                            }
                        }
                    } else {
                        AccessibilityEngine.mockBack();
                        continue;
                    }
                }
                if (AccessibilityEngine.checkUpText("暂时没有更多了") == ISTRUE) {
                    showLog("暂时没有更多了点击返回");
                    AccessibilityEngine.mockBack();
                    break  aaa;
                }
                showLog("滑动滑动滑动");
                ScreenEngine.swipe(parseX(450), parseY(1100), parseX(450), parseY(200), 500);
            }else {
                showLog('wode');
                AccessibilityEngine.mockBack();
                break aaa;
            }
        }
        if (AccessibilityEngine.checkUpId(widget.pages.pinglun.titleneirong) == ISTRUE) { //点赞小心
            AccessibilityEngine.mockBack();
        }
        ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动

    }
    showLog("显示执行成功");
    setTaskState("5", "脚本执行完毕");
    throw SyntaxError();

}
var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();